package com.zcx.qshop.conn;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

@HttpInlet(Conn.INLET_JSON_COUPON)
public class JsonCouponAsyGet extends QSAsyGet<JsonCouponAsyGet.Info> {
	
	public String uid;
	
	public JsonCouponAsyGet(String uid, AsyCallBack<Info> asyCallBack) {
		
		super(asyCallBack);
		
		this.uid = uid;
		
 	}
	
	@Override
	public Info parser(JSONObject object) {
		
		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			JSONArray array = object.optJSONArray("couponlist");
			
			for (int i = 0; i < array.length(); i++) {
				
				Info.Coupon coupon = new Info.Coupon();
				
				JSONObject o = array.optJSONObject(i);
				
				coupon.cid = o.optString("cid");
				
				coupon.price = o.optString("price");
				
				coupon.fullprice = o.optString("fullprice");
				
				coupon.begintime = o.optString("begintime");
				
				coupon.endtime = o.optString("endtime");
				
				coupon.statue = o.optString("statue"); 
				
				info.coupons.add(coupon);
				
			}
			
			return info;
			
		}
		
		return null;
		
	}

	public static class Info{
		
		public List<Coupon> coupons = new ArrayList<Coupon>();
		
		public static class Coupon{
			
			public String cid = "", price = "", fullprice = "", begintime = "", endtime = "", statue = "";

		}
		
	}

}
